from django.shortcuts import render,HttpResponse
from .myform import StudentForm
from .models import Student
from django.db.models import Q,F
# Create your views here.Q
# todo
def index(request):
    if request.method == 'GET':
        form = StudentForm()
        return render(request,'student.html',{'form':form})
    if request.method == 'POST':
        # name = request.POST.get('name','')
        # age = request.POST.get('name','')
        form = StudentForm(request.POST)
        if form.is_valid():
            student = Student(**form.cleaned_data)
            student.save()
        else:
            return render(request,'student.html',{'form':form})
        return HttpResponse('录入成功')


def aa(request):
    obj = Student.objects.filter(Q(age__gt=20) & Q(name__istartswith='李')).update(age=F('age')-1)

    print(obj)
    return HttpResponse('ok')